<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Bill extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'bill';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
		'clothbank'
    ];
    
    
    public function purchase()
    {
    	return $this->belongsTo('Purchase', 'purchase_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function getClothbankAttr($value, $data)
    {
    	$infoPurchase = db('purchase')->alias('a')
    					->join('clothbank b','a.clothbank_id=b.id','left')
    					->where('a.id', $data['purchase_id'])
    					->value('b.name');
    	//dump($infoPurchase);
    	return $infoPurchase;
    }



}
